package org.mspring.mlog.web.module.web.ucenter.admin;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.mspring.mlog.entity.Comment;
import org.mspring.mlog.entity.security.User;
import org.mspring.mlog.service.CommentService;
import org.mspring.mlog.support.resolver.QueryParam;
import org.mspring.mlog.support.resolver.SpaceUser;
import org.mspring.mlog.web.query.CommentQueryCriterion;
import org.mspring.platform.persistence.support.Page;
import org.mspring.platform.persistence.support.Sort;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * 
 * @author Hu HongYu
 * 
 */
@Controller
@RequestMapping("/u/{username}/admin/comment")
public class UCenterAdmin_CommentWidget {

    @Autowired
    private CommentService commentService;

    @SuppressWarnings("rawtypes")
    @RequestMapping("/list")
    public String list(@SpaceUser(pathVariable = "username") User user, @ModelAttribute Page<Comment> commentPage, @ModelAttribute Comment comment, @QueryParam Map queryParams, HttpServletRequest request, HttpServletResponse response, Model model) {
        if (user == null) {
            return "skin:/error/404";
        }
        if (commentPage == null) {
            commentPage = new Page<Comment>();
        }
        if (comment == null) {
            comment = new Comment();
        }
        commentPage.setSort(new Sort("id desc", ""));
        commentPage = commentService.listPage(new CommentQueryCriterion(queryParams), commentPage);
        model.addAttribute("commentPage", commentPage);
        return "skin:/ucenter/admin/comment/list";
    }
}
